﻿using BreacherCreature.Components.Lights;
using King.Engine.Core;
using King.Engine.GameObjects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BreacherCreature.GameObjects
{
    class LightSource : GameObject
    {
        static LightSource()
        {
            var controls = new Dictionary<LightControl, Keys>()
            {
                { LightControl.RotateLeft, Keys.Left },
                { LightControl.RotateRight, Keys.Right }
            };
            Input<LightControl>.Initialize(controls);
        }

        public LightSource(int x, int y, float fov, Color lightColor, Vector2 lightOffset, int framesOn, int framesOff, bool startOn) : base()
        {
            this.Bounds = new Rectangle(x, y, 100, 100);

            AddComponent(new LightCone(fov, lightColor, lightOffset, framesOn, framesOff, startOn));
            AddComponent(new LightArea(400, 200, 50, 200, Color.Fuchsia, 60, 240, false));
        }

        #region Protected Methods

        protected override void UpdateAfterComponents(GameTime gameTime)
        {
 	        if (ControlPressed(LightControl.RotateLeft))
            {
                Rotation += .05f;
            }
            else if (ControlPressed(LightControl.RotateRight))
            {
                Rotation -= .05f;
            }
        }
        

        #endregion


        #region Private Methods

        private bool ControlPressed(LightControl control)
        {
            return Input<LightControl>.ControlPressed(control);
        }

        private bool ControlTapped(LightControl control)
        {
            return Input<LightControl>.ControlTapped(control);
        }

        #endregion

        public enum LightControl
        {
            RotateLeft,
            RotateRight
        }
    }
}
